﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="appVersion.aspx.cs" Inherits="Langchur.appmvp.appVersion" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>版本管理</title>
    <link href="../js/element-ui-2.15.14/index.css" rel="stylesheet" />
</head>
<body>
    <div id="app_vm" class="body-controller" style="background: #fff;">
        <el-row style="border: 1px solid #dcdfe6; padding-top:10px">
            <el-col :span="6" style="padding-left:10px;padding-right:10px;"> 
               <%-- <div>
                    <el-button style="width:100%; margin-bottom:10px;" @click="newLv1">添加大版本</el-button> 
                </div>--%>
                <div style="height:73vh; overflow:auto;">
                    <el-tree
                          :data="treedata" 
                          node-key="id" 
                          default-expand-all
                          :expand-on-click-node="false"
                          @node-click="handleNodeClick" >
                          <span class="custom-tree-node" slot-scope="{ node, data }">
                            <span>{{ node.label }}</span>
                            <span> 
                                <i v-show="node.data.PID==0" style="border: 1px solid;border-radius: 50%; cursor:pointer;" @click="temptree(node)" class="el-icon-plus"></i>
                            </span>
                          </span>
                        </el-tree>
                </div> 
            </el-col>
            <el-col :span="18" style="padding-left:10px;padding-right:10px;"> 
                <div v-if="data.ID > 0">
                    <div style="margin-top:15px;">
                        <div>
                            <div>
                                <el-form ref="data" :model="data" label-width="80px">  
                                    <el-form-item label="版本文件">
                                        <div v-if="data.Src!=''">
                                             <el-link type="primary" :href="data.Src" >文件下载</el-link>
                                        </div>
                                        <div v-else>
                                            <el-upload
                                              class="upload-demo"
                                              action="/ApiFilter/UploadFiles.ashx" 
                                              multiple
                                              :show-file-list="false"
                                              :limit="1"
                                              :on-change="uploadsucc"
                                              >
                                              <el-button size="small" type="primary">点击上传</el-button>
                                              <div slot="tip" class="el-upload__tip">文件必须widget.zip</div>
                                            </el-upload>
                                        </div>  
                                    </el-form-item>
                                    <el-form-item label="版本描述">
                                        <el-input type="textarea" v-model="data.Description"></el-input>
                                    </el-form-item> 
                                    <el-form-item>
                                        <el-button type="primary" @click="savebase">保存</el-button> 
                                        <el-button type="danger" @click="delbase">删除</el-button> 
                                    </el-form-item>
                                </el-form>
                            </div> 
                        </div>  
                    </div>
                </div>
                 <div v-else>
                     未选择节点
                 </div> 
            </el-col>
        </el-row>
    </div>
</body>
</html>
<script src="../js/vue.min.js"></script>
<script src="../js/jquery-3.7.1.min.js"></script>
<script src="../js/validate.js"></script>
<script src="../js/ktlapi2.js"></script> 
<script src="../js/element-ui-2.15.14/index.js"></script>



<script>
    var questionsAPP = new Vue({
        el: "#app_vm",
        data() {
            return { 
                treedata: [],
                data: {
                    "ID": 0,
                    "PID": 0,
                    "VersionNo": "", 
                    "Description": "",
                    "Src": "", 
                },
            }
        },
        computed: { 
        },
        methods: {
            uploadsucc(files, fileList) { 
                //this.data.Src = files.response[0].file; 
                try {
                    this.data.Src = files.response[0].file; 
                } catch (e) {

                }
            },
            savebase() {
                ktlapi2({
                    name: "OLP_SaveVersion",
                    data: {
                        "ID": this.data.ID,
                        "Desc": this.data.Description,
                        "Src": "https://Langchur.abc5g.com"+this.data.Src
                    }
                }).then(resp => {
                    alert('保存完成');
                });
            },
            delbase() {
                if (window.confirm("确认删除？")) {
                    ktlapi2({
                        name: "OLP_DelVersion",
                        data: {
                            "ID": this.data.ID
                        }
                    }).then(resp => {
                        alert("删除成功");
                    });

                }
            },
            newLv1() {

            },
            handleNodeClick(data) {
                this.data.PID = data.PID;
                this.data.ID = data.id;
                this.data.VersionNo = data.label;
                this.data.Description = data.Description;
                this.data.Src = data.Src;
            },
            temptree(item) {
                console.log(item);
                ktlapi2({
                    name: "OLP_NewSubVersion",
                    data: {  
                        "Pid": item.key
                    }
                }).then(resp => {
                    var row = deconResponse(resp)[0];
                    //var item = this.treedata.filter(x => {
                    //    return x.id == this.data.ID
                    //})[0];
                    console.log(item);
                    item.children.push({
                        "id": row["ID"],
                        "label": row["Title"],
                        "Descrption": row["Descrption"],
                        "PID": row["PID"],
                        "treeSort": row["Sort"]
                    });

                    //this.treedata = JSON.parse(JSON.stringify(this.treedata));
                });
            },
            init() { 
                ktlapi2({
                    name: "OLP_APPAllVersion",
                    apiurl: OT.ProcSet,
                    data: {
                    }
                }).then(resp => {
                    this.treedata = treeJson(resp.data.tables[0].table, "id", "PID"); 
                })
            }
        },
        mounted() {
            // 查询学段信息
            this.init()
        },
    });

</script>